package org.ss.psci.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.ss.psci.entity.PmBudgetDetails;

/**
 * Data access object (DAO) for domain model class PmBudgetDetails.
 * 
 * @see org.ss.psci.entity.PmBudgetDetails
 * @author MyEclipse Persistence Tools
 */

public class PmBudgetDetailsDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(PmBudgetDetailsDAO.class);
	// property constants
	public static final String TOTAL = "total";
	public static final String PER_PRICE = "perPrice";
	public static final String USE_NUM = "useNum";
	public static final String MAN_PRICE = "manPrice";
	public static final String TOOLS_PRICE = "toolsPrice";
	public static final String MARCHINE_PRICE = "marchinePrice";
	public static final String PERCENT = "percent";

	protected void initDao() {
		// do nothing
	}

	public void save(PmBudgetDetails transientInstance) {
		log.debug("saving PmBudgetDetails instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(PmBudgetDetails persistentInstance) {
		log.debug("deleting PmBudgetDetails instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public PmBudgetDetails findById(java.lang.Integer id) {
		log.debug("getting PmBudgetDetails instance with id: " + id);
		try {
			PmBudgetDetails instance = (PmBudgetDetails) getHibernateTemplate()
					.get("org.ss.psci.entity.PmBudgetDetails", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(PmBudgetDetails instance) {
		log.debug("finding PmBudgetDetails instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding PmBudgetDetails instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from PmBudgetDetails as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByTotal(Object total) {
		return findByProperty(TOTAL, total);
	}

	public List findByPerPrice(Object perPrice) {
		return findByProperty(PER_PRICE, perPrice);
	}

	public List findByUseNum(Object useNum) {
		return findByProperty(USE_NUM, useNum);
	}

	public List findByManPrice(Object manPrice) {
		return findByProperty(MAN_PRICE, manPrice);
	}

	public List findByToolsPrice(Object toolsPrice) {
		return findByProperty(TOOLS_PRICE, toolsPrice);
	}

	public List findByMarchinePrice(Object marchinePrice) {
		return findByProperty(MARCHINE_PRICE, marchinePrice);
	}

	public List findByPercent(Object percent) {
		return findByProperty(PERCENT, percent);
	}

	public List findAll() {
		log.debug("finding all PmBudgetDetails instances");
		try {
			String queryString = "from PmBudgetDetails";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public PmBudgetDetails merge(PmBudgetDetails detachedInstance) {
		log.debug("merging PmBudgetDetails instance");
		try {
			PmBudgetDetails result = (PmBudgetDetails) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(PmBudgetDetails instance) {
		log.debug("attaching dirty PmBudgetDetails instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(PmBudgetDetails instance) {
		log.debug("attaching clean PmBudgetDetails instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static PmBudgetDetailsDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (PmBudgetDetailsDAO) ctx.getBean("PmBudgetDetailsDAO");
	}
}